package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.zin.viewpagerfragment.R;


import java.util.List;

import entity.ListBean;
import util.Utils;


public class NewsAdapter extends BaseAdapter {







    //** 数据集合 *//*
    List<ListBean> list;
    //** 反射器 *//*
    LayoutInflater inflater;

    BitmapUtils bitmapUtils;


    public NewsAdapter(Context context){
        inflater = LayoutInflater.from(context);
        bitmapUtils = Utils.getInstance();
    }


    public void setList(List<ListBean> list) {
        this.list = list;
        System.out.println(list.size()+"adpterlist_size==========");
    }

    @Override
    public int getCount() {
        return (list == null)? 0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


      //  System.out.println("dddddddddddaaaaaaaa");

        ViewHolder  holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.layout_news_item, null);
            holder = new ViewHolder();
            holder.logo = (ImageView) convertView.findViewById(R.id.iv_img);
            holder.title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.pubdate = (TextView) convertView.findViewById(R.id.tv_pub_date);

            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
       ListBean item = list.get(position);
        bitmapUtils.display(holder.logo,item.getImgurl());
      //  System.out.println("adpterurl++++"+item.getImgurl());
        holder.title.setText(item.getTitle());
        holder.pubdate.setText(item.getTime());

        return convertView;
    }

    public static class ViewHolder{
        ImageView logo;
        TextView title;
        TextView pubdate;

    }
}